package com.java.system.controller;


import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;

import java.net.URL;

/**
 * @ClassName: GetLocation
 * @Description:
 * @Version: v1.0.0
 * @Author: Fu Hao
 * @Date: 2019/10/16 0016 下午 2:02
 * Modification History:
 * Date           Author      Version     Description
 * -------------------------------------------------------------
 * 2019/10/16 0016        Fu Hao      v1.0.0         创建
 */
//java根据经纬度获取地址
public class GetLocation {
    /*public static void main(String[] args) {
        // lat 39.97646
        //log 116.3039
        *//*String add = getAdd("116.3039", "39.97646");
        JSONObject jsonObject = JSONObject.fromObject(add);

        JSONArray jsonArray = null;
        try {
            jsonArray = JSONArray.fromObject(jsonObject.get("addrList"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        JSONObject j_2 = JSONObject.fromObject(jsonArray.get(0));
        String allAdd = null;
        try {
            allAdd = j_2.get("admName");
        } catch (Exception e) {
            e.printStackTrace();
        }
        String arr[] = allAdd.split(",");
        System.out.println("省："+arr[0]+"\n市："+arr[1]+"\n区："+arr[2]);*//*
    }
*//*
    public static String getAdd(String log, String lat ){
        //lat 小  log  大
        //参数解释: 纬度,经度 type 001 (100代表道路，010代表POI，001代表门址，111可以同时显示前三项)
        String urlString = "http://gc.ditu.aliyun.com/regeocoding?l="+lat+","+log+"&type=010";
        String res = "";
        try {
            URL url = new URL(urlString);
            java.net.HttpURLConnection conn = (java.net.HttpURLConnection)url.openConnection();
            conn.setDoOutput(true);
            conn.setRequestMethod("POST");
            java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(conn.getInputStream(),"UTF-8"));
            String line;
            while ((line = in.readLine()) != null) {
                res += line+"\n";
            }
            in.close();
        } catch (Exception e) {
            System.out.println("error in wapaction,and e is " + e.getMessage());
        }
        System.out.println(res);
        return res;
    }*/

}
